package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.business.domain.TSmjMachineList;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TServerMerInfo;
import com.ruoyi.business.service.ITServerMerInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户码商关系Controller
 * 
 * @author ruoyi
 * @date 2024-11-02
 */
@Controller
@RequestMapping("/business/tServerMerInfo")
public class TServerMerInfoController extends BaseController
{
    private String prefix = "business/tServerMerInfo";

    @Autowired
    private ITServerMerInfoService tServerMerInfoService;
    @Autowired
    private ISysUserService sysUserService;
    @RequiresPermissions("business:tServerMerInfo:view")
    @GetMapping()
    public String tServerMerInfo()
    {
        return prefix + "/tServerMerInfo";
    }

    /**
     * 查询商户码商关系列表
     */
    @RequiresPermissions("business:tServerMerInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TServerMerInfo tServerMerInfo)
    {
        startPage();
        List<TServerMerInfo> list = tServerMerInfoService.selectTServerMerInfoList(tServerMerInfo);
        return getDataTable(list);
    }

    /**
     * 导出商户码商关系列表
     */
    @RequiresPermissions("business:tServerMerInfo:export")
    @Log(title = "商户码商关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TServerMerInfo tServerMerInfo)
    {
        List<TServerMerInfo> list = tServerMerInfoService.selectTServerMerInfoList(tServerMerInfo);
        ExcelUtil<TServerMerInfo> util = new ExcelUtil<TServerMerInfo>(TServerMerInfo.class);
        return util.exportExcel(list, "商户码商关系数据");
    }

    /**
     * 新增商户码商关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户码商关系
     */
    @RequiresPermissions("business:tServerMerInfo:add")
    @Log(title = "商户码商关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TServerMerInfo tServerMerInfo)
    {
        return toAjax(tServerMerInfoService.insertTServerMerInfo(tServerMerInfo));
    }

    /**
     * 修改商户码商关系
     */
    @RequiresPermissions("business:tServerMerInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TServerMerInfo tServerMerInfo = tServerMerInfoService.selectTServerMerInfoById(id);
        mmap.put("tServerMerInfo", tServerMerInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户码商关系
     */
    @RequiresPermissions("business:tServerMerInfo:edit")
    @Log(title = "商户码商关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TServerMerInfo tServerMerInfo)
    {
        return toAjax(tServerMerInfoService.updateTServerMerInfo(tServerMerInfo));
    }

    /**
     * 删除商户码商关系
     */
    @RequiresPermissions("business:tServerMerInfo:remove")
    @Log(title = "商户码商关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tServerMerInfoService.deleteTServerMerInfoByIds(ids));
    }

    @Log(title = "用户收款号状态变更", businessType = BusinessType.UPDATE)
    @RequiresPermissions("business:tServerMerInfo:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(TServerMerInfo tServerMerInfo) {
        TServerMerInfo newTServerMerInfo = tServerMerInfoService.selectTServerMerInfoById(tServerMerInfo.getId());
        newTServerMerInfo.setStatus(tServerMerInfo.getStatus());
        return toAjax(tServerMerInfoService.updateTServerMerInfo(newTServerMerInfo));
//        return toAjax(tNginxInfoService.updateTNginxInfo(tNginxInfo));
    }
}
